package ee.ttu.serge;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import ee.ttu.serge.container.dynamicarray.DynamicArray;
import ee.ttu.serge.container.priorityqueue.PriorityQueue;
import ee.ttu.serge.container.stack.Stack;

public class Main {
   
   public static void main(String[] args) throws IOException {  
      Stack stack = new Stack();
      PriorityQueue queue = new PriorityQueue();
      queue.create();
      
      List<Integer> list = FileHelper.read("input.in");
      List<Integer> outStack = new ArrayList<Integer>();
      List<Integer> outQueue = new ArrayList<Integer>();
      for (int i : list) {
         //System.out.println(i);
         if (i > 0) {
            stack.push(i);
            queue.enqueue(i);
         } else if (i == 0) {
            while (!stack.isEmpty()) {
               outStack.add(stack.pop());        
               outQueue.add(queue.dequeue());      
            }
         } else if (i < 0) {
            int abs = Math.abs(i);
            for (int j = 0; j < abs; j++) {
               if (!stack.isEmpty()) outStack.add(stack.pop());
               if (!queue.isEmpty())  outQueue.add(queue.dequeue());
            }
         }
      }
      FileHelper.write("output-mag.out", outStack);
      FileHelper.write("output-pri.out", outQueue);
   }

}
